var objControllerGeral = {
	
		init: function( noModulo, noController )
		{
			$( "#btnPesquisar" ).click( function( ){  objControllerGeral.pesquisar( noModulo, noController )} );	
			$('#btnTodos').click(function(){
				//objModal.loading( {id:'loading', title:'Aguarde...'} );
				$('#sysConteudo').load( URL_BASE + noModulo + '/' + noController , function(){ objModal.close('loading')  } );
			});			
			//$( "#btnFrmCadastro" ).click( this.frmCadastrar( '', noModulo, noController ) );	
			var paramJSON 		= {};
			paramJSON.url 		= noModulo+'/'+noController+'/listar';
			paramJSON.form		= 'frmPesquisar';
			paramJSON.type		= TYPE_RESPONSE_HTML; 
			Action.doPostValidate( paramJSON,  function( html )
							                   {  
											       $('#list_grid').html( html );
							                   });	
		},
		
		
		pesquisar: function( noModulo, noController )
		{
			//objModal.loading( {id:'loading', title:'Aguarde...'} );
			var paramJSON 		= {};
			paramJSON.url 		= noModulo + '/' + noController + '/listar';
			paramJSON.form		= 'frmPesquisar';
			paramJSON.type		= TYPE_RESPONSE_HTML; 
			Action.doPostValidate( paramJSON,  function( html )
							                   {  
											       $('#list_grid').html( html );
											       objModal.close('loading');
							                   });			
		},
		
		addEventList: function( noChavePK, noModulo, noController )
		{
			$('.edit').click(function(){
				var tipo_busca = $('#tipo_busca').val();
	    	    var palavra_chave = $('#palavra_chave').val();
	    	    $('#tipo_busca').val( noChavePK );
	    	    $('#palavra_chave').val( this.alt );
	    	    objControllerGeral.frmCadastrar( 'frmPesquisar', noModulo, noController );
	    	   
	    	    $('#tipo_busca').val( tipo_busca );
	    	    $('#palavra_chave').val( palavra_chave );   											    	   
		     }),
		     
			$('.delete').click(function(){	
				var tipo_busca = $('#tipo_busca').val();
	    	    var palavra_chave = $('#palavra_chave').val();
	    	    $('#tipo_busca').val( noChavePK );
	    	    $('#palavra_chave').val( this.alt );				
		        $('#dialogo').dialog({
		            autoOpen: false,
		            width: 400,
		            modal: true,
		            resizable: false,
		            title: 'APAGAR REGISTRO',
		            buttons: {
		                "Confirmar": function() {
		    	    	    objControllerGeral.excluir( noModulo, noController );
		    	    	    $('#tipo_busca').val( tipo_busca );
		    	    	    $('#palavra_chave').val( palavra_chave ); 
		    	    	    $(this).dialog("close");
		                },
		                "Cancelar": function() {
		                    $(this).dialog("close");
		    	    	    $('#tipo_busca').val( tipo_busca );
		    	    	    $('#palavra_chave').val( palavra_chave ); 		                    
		                }
		            }
		        });
		        $('#dialogo').html('<h1>Tem certeza que deseja excluir este registro?</h1>');
		        $('#dialogo').dialog('open');
  						        
		        
		     });		     
		},
		
		frmCadastrar: function( no_form, noModulo, noController )
		{
			if( no_form == '' )
			{
				var no_form = 'frmCadastro';
			}
			//objModal.loading( {id:'loading', title:'Aguarde...'} );
			var paramJSON 		= {};
			paramJSON.url 		= noModulo + '/' + noController + '/cadastro';
			paramJSON.form		= no_form;
			paramJSON.type 		= TYPE_RESPONSE_HTML;
			Action.doPostValidate( paramJSON, function( html )
					                          {  
												   $('#sysConteudo').html( html );
												   objModal.close('loading');  
					                          });
		},
		
		addEventFrm: function( noModulo, noController )
		{
			$('#btnFechar').click(function(){
				objModal.loading( {id:'loading', title:'Aguarde...'} );
				$('#sysConteudo').load( URL_BASE + noModulo + '/' + noController , function(){ objModal.close('loading')  } );
			});
			
			$('#btnSalvar').click(function(){
				objControllerGeral.salvar( noModulo, noController );
			});
		},
		
		salvar: function( noModulo, noController )
		{
			//objModal.loading( {id:'loading', title:'Aguarde...'} );
			var paramJSON 		= {};
			paramJSON.url 		= noModulo + '/' + noController + '/' + 'salvar';
			paramJSON.form		= 'frmCadastro';
			paramJSON.type 		= TYPE_RESPONSE_JSON;
			Action.doPostValidate( paramJSON, function( json )
											  {
											      Messenger.init( json, function()
											      {
											    	  
											    	  if( json.strStatus == STATUS_OK )
												      {
												    	  $('#frmCadastro').get(0).reset();
												    	  objModal.close('loading');
												      }
											    	  objModal.close('loading');
											      });											      
											  });
			return this;
		},
		
		excluir: function( noModulo, noController )
		{
			//objModal.loading( {id:'loading', title:'Aguarde...'} );
			var paramJSON 		= {};
			paramJSON.url 		= noModulo + '/' + noController + '/excluir';
			paramJSON.form		= 'frmPesquisar';
			paramJSON.type 		= TYPE_RESPONSE_JSON;
			Action.doPostValidate( paramJSON, function( json )
											  {
											      Messenger.init( json, function()
											      {
											    	  if( json.strStatus == STATUS_OK )
												      {
											    		  $('#sysConteudo').load( URL_BASE + noModulo + '/' + noController );
											    		  objModal.close('loading');
												      }
											    	  objModal.close('loading');
											      });											      
											  });
			return this;
		}		
};